#!/usr/bin/env python3
"""
验证推荐API响应
"""
import requests
import json
import time

def test_recommend_api():
    """测试推荐API"""
    print("🧪 测试推荐买入API...")
    
    try:
        start_time = time.time()
        response = requests.get("http://localhost:8000/api/stocks/recommended/buy", timeout=10)
        response_time = time.time() - start_time
        
        print(f"⏱️ 响应时间: {response_time:.2f}秒")
        print(f"📊 状态码: {response.status_code}")
        
        if response.status_code == 200:
            data = response.json()
            print(f"✅ 成功返回 {len(data)} 只推荐股票")
            
            if data:
                print("\n📈 推荐股票列表:")
                for i, stock in enumerate(data[:3], 1):  # 显示前3只
                    print(f"  {i}. {stock.get('symbol')} - {stock.get('name')}")
                    print(f"     当前价: ¥{stock.get('currentPrice')}")
                    print(f"     买入价: ¥{stock.get('buyPrice')}")
                    print(f"     信号: {stock.get('signalType')} (强度: {stock.get('signalStrength')})")
                    print(f"     原因: {stock.get('signalReason', '')[:50]}...")
                    print()
        else:
            print(f"❌ API请求失败: {response.status_code}")
            print(f"响应内容: {response.text}")
            
    except Exception as e:
        print(f"❌ 请求异常: {e}")

if __name__ == "__main__":
    test_recommend_api()

